var onlineRecordAddCtrl  = new XFApp.client();
$.views.converters({
	
});

XFApp.client.prototype.onlineRecordAdd = {
		successCode : "10000",	
		urlItems : {			
			saveStoreURL: basePath+"/userCenter/enOnlineRecord/saveRecord",
		},
		
		formValidate : function(){
			$("#editForm").validate({
		        rules: {
		        	companyName: "required",
		        	companyAddr: "required",
		        	contact: "required",
		        	tel: "required",
		        	files: "required"
				  },
				 messages: {
					 companyName: "请填写申报企业名称",
			         companyAddr: "请填写申报企业地址",
			         contact: "请填写联系人",
			         tel: "请填写联系电话",
			         files:"请选择要上传企业资料附件 "			        	    
			         }
		    });
			$("#editForm").validate();
		},
		
		event : function (){			
			_this = this;
			
			$("#submitBtn").on("click",function(){				
				if($("#editForm").validate().form()){
					onlineRecordAddCtrl.onlineRecordAdd.ajaxFileUpload();
				}				
			});
			//表单验证
			_this.formValidate();	
		},		
		
		
		ajaxFileUpload : function (){		    
			var entity = {
				companyName : $("#companyName").val(),
				companyAddr : $("#companyAddr").val(),
				contact : $("#contact").val()	,
				tel : $("#tel").val(),				
				applyRemark : $("#applyRemark").val()
			} 		
			//基于ajaxfileUpload.js实现
			$.ajaxFileUpload({
				url : _this.urlItems.saveStoreURL,
				secureuri : false,
				data:entity,
				fileElementId : ['applyFilePath','companyFilePath'],//现使用方法
				dataType : 'json',
				success : function(data) {
					if (data.code == _this.successCode) {
						window.webDialogUtil.alert("提示",data.msg);	
					} else {
						window.webDialogUtil.alert("提示",data.msg);
					}
				},
				error : function(data, status, e){
					window.webDialogUtil.alert("提示",data.msg);
				}
			});
		},
		
		save : function(){
			
			var entity = {
				companyName : $("#companyName").val(),
				companyAddr : $("#companyAddr").val(),
				contact : $("#contact").val()	,
				tel : $("#tel").val(),				
				applyRemark : $("#applyRemark").val()
			}
	    	
	    	$.ajax({
	    		url :_this.urlItems.saveStoreURL,
	    		data : entity,
	    		dataType : "json",
	    		type : 'post',
	    		success : function(data) {				
	    			if(data.code==_this.successCode){ 
	    				window.webDialogUtil.alert("提示",data.msg);	
	    				$('#editForm')[0].reset();  
	    			}else{
	    				window.webDialogUtil.alert("提示",data.msg);
	    			}
	    		}
	    	});	
		},
		
},

$(function(){	
	onlineRecordAddCtrl.onlineRecordAdd.event();
	
});